/**
 * Copyright (c) 2013 An Yaming,  All Rights Reserved
 */
package so.shanku.essential.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import aym.util.json.JsonMap;
import so.shanku.essential.R;
import so.shanku.essential.utils.Confing;

import java.util.List;
import java.util.Map;

/**
 * @author tanghuan
 * @ClassName: ProductCommentAdapter
 * @Description: TODO(商品的评论的数据适配器)
 * @date 2014年12月3日 下午8:00:27
 */
public class PaymentListAdapter extends MyBaseAdapter {


	private int selectId = -1;

	public PaymentListAdapter(Context context) {
		super(context);
	}

	public PaymentListAdapter(Context context, List<? extends Map<String, ?>> datas) {
		super(context, datas);
	}

	public void setSelected(int str) {
		selectId = str;
		notifyDataSetChanged();
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		PaymentListAdapterViewHolder paymentListAdapterViewHolder;
		if (convertView == null) {
			convertView = layoutInflater.inflate(R.layout.item_shopping_zhifu_peisong_way, null);
			paymentListAdapterViewHolder = new PaymentListAdapterViewHolder();
			convertView.setTag(paymentListAdapterViewHolder);
			paymentListAdapterViewHolder.payLogo_iv = (ImageView) convertView.findViewById(R.id.pay_logo);
			paymentListAdapterViewHolder.payName_tv = (TextView) convertView.findViewById(R.id.item_shopping_addorder_gvns_payment);
			paymentListAdapterViewHolder.pay_selected_iv = (ImageView) convertView.findViewById(R.id.pay_select_iv);
		} else {
			paymentListAdapterViewHolder = (PaymentListAdapterViewHolder) convertView.getTag();
		}
		if (selectId == position) {
			//设置背景（就是选中行的背景）
			paymentListAdapterViewHolder.pay_selected_iv.setSelected(true);
		} else {
			//设置背景（就是未选中行的背景）
			paymentListAdapterViewHolder.pay_selected_iv.setSelected(false);
		}
		JsonMap map = (JsonMap) datas.get(position);
		String payIdStr = map.getStringNoNull("Id");
		int payId=0;
		try {
			payId=Integer.parseInt(payIdStr);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}

		if (payId==Confing.ZHIFUBAO_PAYID) {
			paymentListAdapterViewHolder.payLogo_iv.setVisibility(View.VISIBLE);
			paymentListAdapterViewHolder.payLogo_iv.setImageResource(R.drawable.pay_zhifubao);
		} else if (payId==3) {
			paymentListAdapterViewHolder.payLogo_iv.setVisibility(View.INVISIBLE);
		} else if (payId==4) {
			paymentListAdapterViewHolder.payLogo_iv.setVisibility(View.INVISIBLE);
		} else if (payId==Confing.UNION_PAYID) {
			paymentListAdapterViewHolder.payLogo_iv.setVisibility(View.VISIBLE);
			paymentListAdapterViewHolder.payLogo_iv.setImageResource(R.drawable.pay_union);
		} else if (payId==6) {
			paymentListAdapterViewHolder.payLogo_iv.setVisibility(View.VISIBLE);
			paymentListAdapterViewHolder.payLogo_iv.setImageResource(R.drawable.pay_weichat);
		} else if (payId==Confing.WEICHAT_PAYID) {
			paymentListAdapterViewHolder.payLogo_iv.setVisibility(View.VISIBLE);
			paymentListAdapterViewHolder.payLogo_iv.setImageResource(R.drawable.pay_weichat);
		}
		paymentListAdapterViewHolder.payName_tv.setText(map.getStringNoNull("Name"));
		return convertView;
	}

	class PaymentListAdapterViewHolder {
		ImageView payLogo_iv;
		TextView payName_tv;
		ImageView pay_selected_iv;
	}
}
